let sourceData = [
  { col_0: "粗抛槽", col_1: "初配", col_2: "温度", value: "80", unit: "" },
  { col_0: "粗抛槽", col_1: "初配", col_2: "时间", value: "9999", unit: "" },
  { col_0: "粗抛槽", col_1: "补液", col_2: "CDI", value: "1000", unit: "" },
  { col_0: "粗抛槽", col_1: "补液", col_2: "HDI", value: "9000", unit: "" },
  { col_0: "粗抛槽", col_1: "补液", col_2: "KOH", value: "800", unit: "" },
  { col_0: "粗抛槽", col_1: "初配", col_2: "KOH", value: "40000", unit: "" },

  { col_0: "预清洗槽", col_1: "初配", col_2: "温度", value: "70", unit: "" },
  { col_0: "制绒槽1", col_1: "初配", col_2: "温度", value: "82", unit: "" },
  { col_0: "制绒槽2", col_1: "初配", col_2: "温度", value: "82", unit: "" },
  { col_0: "制绒槽3", col_1: "初配", col_2: "温度", value: "82", unit: "" },
  { col_0: "慢提拉槽", col_1: "", col_2: "温度", value: "70", unit: "" },
  { col_0: "风干槽1", col_1: "", col_2: "温度", value: "90", unit: "" },
  { col_0: "风干槽2", col_1: "", col_2: "温度", value: "90", unit: "" },
  { col_0: "风干槽3", col_1: "", col_2: "温度", value: "90", unit: "" },
  { col_0: "风干槽4", col_1: "", col_2: "温度", value: "90", unit: "" },
  { col_0: "预清洗槽", col_1: "初配", col_2: "时间", value: "135", unit: "" },
  { col_0: "制绒槽1", col_1: "初配", col_2: "时间", value: "430", unit: "" },
  { col_0: "制绒槽2", col_1: "初配", col_2: "时间", value: "430", unit: "" },
  { col_0: "制绒槽3", col_1: "初配", col_2: "时间", value: "430", unit: "" },
  { col_0: "臭氧槽", col_1: "初配", col_2: "时间", value: "120", unit: "" },
  { col_0: "酸洗1槽", col_1: "初配", col_2: "时间", value: "", unit: "" },
  { col_0: "酸洗1槽", col_1: "初配", col_2: "时间", value: "", unit: "" },
  { col_0: "慢提拉槽", col_1: "", col_2: "时间", value: "10", unit: "" },
  { col_0: "风干槽1", col_1: "", col_2: "时间", value: "560", unit: "" },
  { col_0: "风干槽2", col_1: "", col_2: "时间", value: "560", unit: "" },
  { col_0: "风干槽3", col_1: "", col_2: "时间", value: "560", unit: "" },
  { col_0: "风干槽4", col_1: "", col_2: "时间", value: "560", unit: "" },
  { col_0: "预清洗槽", col_1: "补液", col_2: "CDI", value: "1000", unit: "" },
  { col_0: "预清洗槽", col_1: "补液", col_2: "H2O2", value: "500", unit: "" },
  { col_0: "预清洗槽", col_1: "补液", col_2: "HDI", value: "2000", unit: "" },
  { col_0: "预清洗槽", col_1: "补液", col_2: "KOH", value: "90", unit: "" },
  { col_0: "制绒槽1", col_1: "补液", col_2: "ADDI", value: "200", unit: "" },
  { col_0: "制绒槽1", col_1: "补液", col_2: "HDI", value: "10000", unit: "" },
];

sourceData.forEach((item, index) => {
  item["id"] = index + "-1";
});

/*
 * @Description: js 对json数组按照几个字段排序
 * @Version: 1.0
 * @Autor: wq
 * @Date: 2021-08-27 16:06:17
 * @LastEditors: wq
 * @LastEditTime: 2021-08-27 16:07:46
 */

function sortObjectArray(objArr, keyArr, type) {
  for (var x = 0; x < objArr.length; x++) {
    objArr[x].oldIndex = x;
  }
  if (type !== undefined && type !== "asc" && type !== "desc") {
    return "error";
  }
  var order = 1;
  if (type !== undefined && type === "desc") {
    order = -1;
  }
  var key = keyArr[0];
  objArr.sort(function (objA, objB) {
    if (objA[key] > objB[key]) {
      return order;
    } else if (objA[key] < objB[key]) {
      return 0 - order;
    } else {
      if (objA.oldIndex > objB.oldIndex) {
        return order;
      } else if (objA.oldIndex < objB.oldIndex) {
        return 0 - order;
      } else {
        return 0;
      }
    }
  });

  for (let i = 1; i < keyArr.length; i++) {
    let key = keyArr[i];
    for (let y = 0; y < objArr.length; y++) {
      objArr[y].oldIndex = y;
    }
    objArr.sort(function (objA, objB) {
      for (let j = 0; j < i; j++) {
        if (objA[keyArr[j]] !== objB[keyArr[j]]) {
          if (objA.oldIndex > objB.oldIndex) {
            return order;
          } else if (objA.oldIndex < objB.oldIndex) {
            return 0 - order;
          } else {
            return 0;
          }
        }
      }
      if (objA[key] > objB[key]) {
        return order;
      } else if (objA[key] < objB[key]) {
        return 0 - order;
      } else {
        if (objA.oldIndex > objB.oldIndex) {
          return order;
        } else if (objA.oldIndex < objB.oldIndex) {
          return 0 - order;
        } else {
          return 0;
        }
      }
    });
  }
  return objArr;
}

sourceData = sortObjectArray(sourceData, ["col_0", "col_1"], "asc");

// sourceData.sort((a, b)=> a.col_0.localeCompare(b.col_0, 'zh')); //a~z 排序
// sourceData.sort((a, b)=> a.col_1.localeCompare(b.col_1, 'zh')); //a~z 排序

export { sourceData };
